package com.soriya.nestlive.controller.api;


import com.soriya.nestlive.entity.PageResult;
import com.soriya.nestlive.entity.param.VideoPublishParam;
import com.soriya.nestlive.entity.vo.VideoDetailVo;
import com.soriya.nestlive.service.VideoService;
import com.soriya.nestlive.util.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/video")
public class VideoApi {

    private final VideoService videoService;

    @Autowired
    public VideoApi(VideoService videoService) {
        this.videoService = videoService;
    }

    @PostMapping("/publishVideo")
    public Result<?> publishVideo(VideoPublishParam param) {
        boolean b = videoService.publishVideo(param);
        return Result.update(b);
    }

    @GetMapping("/{id}")
    public Result<?> getById(@PathVariable Long id) {
        VideoDetailVo detail = videoService.getDetailById(id);
        return Result.success(detail);
    }

    @GetMapping("/channelId/{channelId}/{current}/{page}")
    public Result<?> getByChannelId(@PathVariable Long channelId, @PathVariable Integer current, @PathVariable Integer page) {
        PageResult<VideoDetailVo> pageResult = videoService.getByChannelId(channelId, current, page);
        return Result.success(pageResult);
    }

    @GetMapping("/categoryId/{categoryId}/{current}/{page}")
    public Result<?> getByCategoryId(@PathVariable Long categoryId, @PathVariable Integer current, @PathVariable Integer page) {
        PageResult<VideoDetailVo> pageResult = videoService.getByCategoryId(categoryId, current, page);
        return Result.success(pageResult);
    }

}
